class MedianFinder {
    priority_queue<int> left;
    priority_queue<int,vector<int>,greater<int>> right;
public:
    MedianFinder() {

    }
    
    void addNum(int num) {
        if(left.size()==right.size())
        {
            if(left.empty()||num<=left.top())
            {
                left.push(num);
            }
            else
            {
                right.push(num);
                int rightTop=right.top();
                right.pop();
                left.push(rightTop);
            }
        }
        else if(left.size()==right.size()+1)
        {
            if(num<=left.top())
            {
                left.push(num);
                int leftTop=left.top();
                left.pop();
                right.push(leftTop);
            }
            else 
            {
                right.push(num);
            }
        }
    }
    
    double findMedian() {
        if(left.size()==right.size())return (left.top()+right.top())/2.0;
        else return left.top();

    }
};

/**
 * Your MedianFinder object will be instantiated and called as such:
 * MedianFinder* obj = new MedianFinder();
 * obj->addNum(num);
 * double param_2 = obj->findMedian();
 */
